package com.szxy.backend.content.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.szxy.backend.content.feign.CommonContentFeignClient;
import com.szxy.backend.content.service.ContentService;
import com.szxy.pojo.TbContent;
import com.szxy.utils.PageResult;
import com.szxy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Auther:zwer
 * @Date:2019/9/9 21:00
 * @Description:com.szxy.content.service.impl
 * @Version:1.0
 **/
@Service
public class ContentServiceImpl implements ContentService {

    @Autowired
    private CommonContentFeignClient commonContentFeignClient;

    @Override
    @LcnTransaction
    public Result insertTbContent(TbContent content) {
        try {
            content.setCreated(new Date());
            content.setUpdated(new Date());
            int flag = this.commonContentFeignClient.insertTbContent(content);
            if(flag > 0){
                return Result.ok();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.error("插入失败");
    }

    @Override
    @LcnTransaction
    public Result deleteContentByIds(Long ids) {
        try {
            Integer flag  =
                    this.commonContentFeignClient.deleteContentByIds(ids);
            if(flag > 0){
                return Result.ok();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.error("删除错误");
    }

    @Override
    public Result selectTbContentAllByCategoryId(Long categoryId, Integer page, Integer rows) {
        try {
            PageResult pageResult =
                    this.commonContentFeignClient.selectTbContentAllByCategoryId(categoryId,page,rows);
            return Result.ok(pageResult);
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.error("查询错误");
    }
}
